﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Drawing;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using Infragistics.Windows.DataPresenter;


namespace ReclutamientoCosea
{
	/// <summary>
	/// Interaction logic for usrCurriculum.xaml
	/// </summary>
	public partial class usrCurriculum : UserControl
	{
        public event CerroVentana SeCerroVentana;
        private static AppSettingsReader settings = new AppSettingsReader();

        private Curriculum curriculo = new Curriculum();
        private bool _hayImage = false;
        private bool _modoActualiza = false;
        string filename = "";
        private string _idPersona = "";
        private string _idCandidato = "";
        private Estudios _estudios = new Estudios();
        private Experiencia _experiencia = new Experiencia();
        private int _renglon = 0;
        private int _accion = 0;
        private string _nombreCompleto = " ";

        public string NombreCompleto
        {
            get { return _nombreCompleto; }
            set { _nombreCompleto = value; }
        }

        public string IdCandidato
        {
            get { return _idCandidato; }
            set { _idCandidato = value; }
        }

        public string IdPersona
        {
            get { return _idPersona; }
            set { _idPersona = value; }
        }


		public usrCurriculum()
		{
			this.InitializeComponent();
            this.Loaded += new RoutedEventHandler(usrCurriculum_Loaded);
		}

        
        void usrCurriculum_Loaded(object sender, RoutedEventArgs e)
        {
            bdSQLServer bd = new bdSQLServer ((string)settings.GetValue("cadenaconexion", typeof(string)));
            try
            {
                bd.bdConecta();
                string sql1 = "exec SPObtenCurriculum '{0}'";
                sql1 = string.Format (sql1 ,_idCandidato );
                DataSet ds = bd.dataSetConsulta(sql1, "curr");
                if (ds.Tables["curr"].Rows.Count > 0)
                {


                    DataRow  dr = ds.Tables["curr"].Rows[0];
                    _modoActualiza = true;
                    curriculo.idcandidato = dr["idcandidato"].ToString();
                    curriculo.idcurriculum = dr["idcurriculum"].ToString();
                    curriculo.nombrecompleto = dr["nombrecompleto"].ToString();
                    txtNombreCompleto.Text = curriculo.nombrecompleto.Trim() ;
                    curriculo.expectativasprofesionales = dr["expectativasprofesionales"].ToString();
                    txtExpectativas.Text = curriculo.expectativasprofesionales.Trim();
                    //**Estudios
                    curriculo.estudiosrealizados = dr["estudiosrealizados"].ToString();
                    //**
                    //*Experencia
                    curriculo.experienciaprofesional = dr["experienciaprofesional"].ToString();
                    //**
                    //**Competencias
                    curriculo.competencias = dr["competencias"].ToString();
                    FlowDocument mcFlowDoc = new FlowDocument();
                    Paragraph para = new Paragraph();
                    para.Inlines.Add(new Run(curriculo.competencias));
                    mcFlowDoc.Blocks.Add(para);
                    txtTexto1.Document = mcFlowDoc;

                    //**
                    //**Habilidades
                    curriculo.habilidades = dr["habilidades"].ToString();
                    mcFlowDoc = new FlowDocument();
                    para = new Paragraph();
                    para.Inlines.Add(new Run(curriculo.habilidades));
                    mcFlowDoc.Blocks.Add(para);
                    txtTexto2.Document = mcFlowDoc;
                    //**
                    curriculo.fechaalta = dr["fechaalta"].ToString();
                    bool bActivo = bool.Parse(dr["activo"].ToString());
                    if (bActivo == true)
                        curriculo.activo = "1";
                    else
                        curriculo.activo = "0";
                }
                else
                {
                    _modoActualiza = false;
                }

                sql1 = string.Format("select * from imagenpersona where idpersona = '{0}'",
                    IdPersona);
                
                DataSet ds2 = bd.dataSetConsulta(sql1, "imagen");
                DataTable dt = ds2.Tables["imagen"];
                if (dt.Rows.Count > 0)
                {
                    _hayImage = true;
                    if (dt.Rows[0]["imagen"] != DBNull.Value)
                    {
                        BitmapImage bitImg = new BitmapImage();
                        bitImg.BeginInit();
                        System.IO.Stream ms = new System.IO.MemoryStream((byte[])dt.Rows[0]["imagen"]);
                        bitImg.StreamSource = ms;
                        bitImg.EndInit();
                        imgFoto.Source = bitImg;
                    }
                }
                else
                {
                    _hayImage = false;
                }
                
                dt = null;

                //Ahora cargamos los grids
                CargaGrids();
                lblMensaje.Content = string.Empty;


            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
            finally
            {
                bd.bdCierra();
            }

        }
               

        /// <summary>
        /// True Modo Actualización
        /// False Modo Ingresar nuevo curr
        /// </summary>
        public bool ModoActualiza
        {
            get { return _modoActualiza; }
            set { _modoActualiza = value; }
        }

		private void btnEstudios_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            wDetalleCurriculum wdet = new wDetalleCurriculum();           
            wdet.SeCerroVentana += (objeto) => 
            {
                curriculo.estudiosrealizados = Utilerias.ConvertRichTextBoxContentsToString(objeto);                
            };

            wdet.lblEtiqueta.Content = "Estudios";
            if (_modoActualiza == false)
            {
                wdet.txtTexto.Document.Blocks.Clear();
            }
            else
            {
                FlowDocument mcFlowDoc = new FlowDocument();
                Paragraph para = new Paragraph();
                para.Inlines.Add(new Run(curriculo.estudiosrealizados));
                mcFlowDoc.Blocks.Add(para);
                wdet.txtTexto.Document = mcFlowDoc;
            }
            wdet.ShowDialog();
		}



		private void btnExperiencia_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            wDetalleCurriculum wdet = new wDetalleCurriculum();
            wdet.SeCerroVentana += (objeto) =>
            {
                curriculo.experienciaprofesional = Utilerias.ConvertRichTextBoxContentsToString(objeto);
            };
            wdet.lblEtiqueta.Content = "Experiencia";
            if (_modoActualiza == false)
            {
                wdet.txtTexto.Document.Blocks.Clear();
            }
            else
            {
                FlowDocument mcFlowDoc = new FlowDocument();
                Paragraph para = new Paragraph();
                para.Inlines.Add(new Run(curriculo.experienciaprofesional));
                mcFlowDoc.Blocks.Add(para);
                wdet.txtTexto.Document = mcFlowDoc;
            }
            wdet.ShowDialog();
		}

		private void btnCompetencias_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            wDetalleCurriculum wdet = new wDetalleCurriculum();
            wdet.SeCerroVentana += (objeto) =>
            {
                curriculo.competencias  = Utilerias.ConvertRichTextBoxContentsToString(objeto);
            };
            wdet.lblEtiqueta.Content = "Competencias";
            if (_modoActualiza == false)
            {
                wdet.txtTexto.Document.Blocks.Clear();
            }
            else
            {
                FlowDocument mcFlowDoc = new FlowDocument();
                Paragraph para = new Paragraph();
                para.Inlines.Add(new Run(curriculo.competencias));
                mcFlowDoc.Blocks.Add(para);
                wdet.txtTexto.Document = mcFlowDoc;
            }
            wdet.ShowDialog();
		}

		private void btnHabilidades_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            wDetalleCurriculum wdet = new wDetalleCurriculum();
            wdet.SeCerroVentana += (objeto) =>
            {
                curriculo.habilidades = Utilerias.ConvertRichTextBoxContentsToString(objeto);
            };
            wdet.lblEtiqueta.Content = "Habilidades";
            if (_modoActualiza == false)
            {
                wdet.txtTexto.Document.Blocks.Clear();
            }
            else
            {
                FlowDocument mcFlowDoc = new FlowDocument();
                Paragraph para = new Paragraph();
                para.Inlines.Add(new Run(curriculo.habilidades));
                mcFlowDoc.Blocks.Add(para);
                wdet.txtTexto.Document = mcFlowDoc;
            }
            wdet.ShowDialog();
		}

        private void btnFinalizar_Click(object sender, RoutedEventArgs e)
        {
            guardaCurriculum();
            MessageBox.Show("Registro guardado!", "Reclutamiento", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        private void guardaCurriculum()
        {
            try
            {
                SqlConnection cnn = new SqlConnection((string)settings.GetValue("cadenaconexion", typeof(string)));
                cnn.Open();
                SqlCommand cmd = new SqlCommand();
                if (_modoActualiza == true)                
                    cmd = new SqlCommand("SPUpdCurriculum", cnn);
                else 
                    cmd = new SqlCommand("SPInsCurriculum", cnn);

                curriculo.competencias = Utilerias.ConvertRichTextBoxContentsToString(txtTexto1);
                curriculo.habilidades = Utilerias.ConvertRichTextBoxContentsToString(txtTexto2);
                curriculo.estudiosrealizados = " ";
                //curriculo.competencias = " ";                
                curriculo.experienciaprofesional = " ";
                

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sqlidcandidato = new SqlParameter ("@idcandidato", _idCandidato);
                SqlParameter sqlnombrecompleto = new SqlParameter("@nombrecompleto", txtNombreCompleto.Text);
                SqlParameter sqlexpectativasprofesionales = new SqlParameter("@expectativasprofesionales", txtExpectativas.Text);
                SqlParameter sqlestudiosrealizados = new SqlParameter("@estudiosrealizados", curriculo.estudiosrealizados);
                SqlParameter sqlexperienciaprofesional = new SqlParameter("@experienciaprofesional", curriculo.experienciaprofesional);
                SqlParameter sqlcompetencias = new SqlParameter("@competencias", curriculo.competencias);
                SqlParameter sqlhabilidades = new SqlParameter("@habilidades", curriculo.habilidades);
                SqlParameter sqlactivo = new SqlParameter("@activo",SqlDbType.Bit);

                cmd.Parameters.Add(sqlidcandidato);
                cmd.Parameters.Add(sqlnombrecompleto);
                cmd.Parameters.Add(sqlexpectativasprofesionales);
                cmd.Parameters.Add(sqlestudiosrealizados);
                cmd.Parameters.Add(sqlexperienciaprofesional);
                cmd.Parameters.Add(sqlcompetencias);
                cmd.Parameters.Add(sqlhabilidades);
                sqlactivo.Value = 1;
                cmd.Parameters.Add(sqlactivo);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                cmd = null;
                cnn.Close();
                cnn = null;
                
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }

        }



        private void guardaImagen()
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".jpg";
                dlg.Filter = "Imagenes (.jpg)|*.jpg";
                Nullable<bool> result = dlg.ShowDialog();
                if (result == true)
                {
                    filename = dlg.FileName;
                    FileStream fsFoto;
                    //filename = @"C:\Users\VictorHCeja\Pictures\arquitectouniverso.jpg";
                    fsFoto = new FileStream(filename, FileMode.Open);
                    FileInfo fiFoto = new FileInfo(filename);
                    long temp = fiFoto.Length;
                    Int32 lung = Convert.ToInt32(temp);
                    byte[] picture = new byte[lung];
                    fsFoto.Read(picture, 0, lung);
                    fsFoto.Close();

                    SqlConnection cnn = new SqlConnection((string)settings.GetValue("cadenaconexion", typeof(string)));
                    cnn.Open();
                    SqlCommand cmdFoto = new SqlCommand();

                    if (_hayImage == true)
                        cmdFoto = new SqlCommand("SPUpdImagenPersona", cnn);
                    else
                        cmdFoto = new SqlCommand("SPInsImagenPersona", cnn);

                    cmdFoto.CommandType = CommandType.StoredProcedure;
                    SqlParameter sql_IDPersona = new SqlParameter("@idpersona", _idPersona);
                    SqlParameter sql_Foto = new SqlParameter("@imagen", SqlDbType.Image);
                    sql_Foto.Value = picture;
                    cmdFoto.Parameters.Add(sql_IDPersona);
                    cmdFoto.Parameters.Add(sql_Foto);
                    cmdFoto.ExecuteNonQuery();
                    cmdFoto.Dispose();
                    sql_Foto = null;
                    picture = null;
                    cnn.Close();
                    cnn = null;

                    imgFoto.Source = new BitmapImage(new Uri(filename));
                }
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }



        }

        private void btnCargarImagen_Click(object sender, RoutedEventArgs e)
        {
            guardaImagen();
        }

        private void btnSalir_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SeCerroVentana(true);	
        }

        private void btnEntrevista_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            wEntrevista wEntre = new wEntrevista();
            wEntre.objEntreCosea.IdCandidato = _idCandidato;
            wEntre.objEntreCosea.IdUsuario = LogInLogOut.Usuario.idusuario;
            //wEntre.objEntrevista.IdCandidato = _idCandidato;
            //wEntre.objEntrevista.IdUsuario = "B0AE4F75-66AD-DF11-BC3A-005056C00008"; //Este valor se tiene que pasar dinamicamente con el usuario firmado
            wEntre.objEntreCosea.SeCerroVentana += (objeto) =>
            {
                wEntre.Close();
            };
            wEntre.Show();        	
        }

        private void bMas1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            _accion = 0;
            agregar(int.Parse(((Button)sender).Tag.ToString()));
        }

        private void bMenos1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            _accion = 1;
            menos(int.Parse(((Button)sender).Tag.ToString()));
        }

        private void bUpd1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            _accion = 2;
            upd(int.Parse(((Button)sender).Tag.ToString()));
        }


        private void dgExperiencias_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                _accion = 2;
                wCurrEstudios wEstudios = new wCurrEstudios(1, _experiencia);
                wEstudios.Title = "Experiencia";
                wEstudios.Renglon = _renglon;
                wEstudios.Show();
                wEstudios.CerrarVentana += (obj1, obj2) =>
                {
                    if (obj2)
                    {
                        _experiencia = (Experiencia)obj1;
                        guardaGrid(2);
                    }
                };
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void dgExperiencias_RecordActivated(object sender, Infragistics.Windows.DataPresenter.Events.RecordActivatedEventArgs e)
        {
            try
            {
                if (e.Record is DataRecord)
                {
                    // Cast the record passed in as a DataRecord
                    DataRecord myRecord = (DataRecord)e.Record;
                    _renglon = int.Parse(myRecord.Cells[0].Value.ToString());
                    _experiencia.Empresa  = myRecord.Cells[1].Value.ToString();
                    _experiencia.Años = int.Parse (myRecord.Cells[2].Value.ToString());
                    _experiencia.Responsabilidades = myRecord.Cells[3].Value.ToString();
                }
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void dgEstudios_RecordActivated(object sender, Infragistics.Windows.DataPresenter.Events.RecordActivatedEventArgs e)
        {
            try
            {
                if (e.Record is DataRecord)
                {
                    // Cast the record passed in as a DataRecord
                    DataRecord myRecord = (DataRecord)e.Record;
                    _renglon = int.Parse(myRecord.Cells[0].Value.ToString());
                    _estudios.Escuela = myRecord.Cells[1].Value.ToString();
                    _estudios.Carrera = myRecord.Cells[2].Value.ToString();
                    _estudios.Titulo = myRecord.Cells[3].Value.ToString();
                    _estudios.Años = int.Parse(myRecord.Cells[4].Value.ToString());
                }
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void dgEstudios_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                _accion = 2;
                wCurrEstudios wEstudios = new wCurrEstudios(0, _estudios);
                wEstudios.Title = "Estudios";
                wEstudios.Renglon = _renglon;
                wEstudios.Show();
                wEstudios.CerrarVentana += (obj1, obj2) =>
                {
                    if (obj2)
                    {                        
                        _estudios = (Estudios)obj1;
                        guardaGrid(1);
                    }
                };
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void guardaGrid(int grid)
        {
            string SQLBase = "";
            string SQLFinal = "";
            try
            {
                switch (grid)
                {
                    case 1:
                        SQLBase = "exec SPUpdEstudios '{0}','{1}','{2}','{3}','{4}',{5}";
                        SQLFinal = string.Format(SQLBase, _idCandidato,_estudios.Escuela,_estudios.Carrera,_estudios.Titulo,_estudios.Años,_renglon);
                        break;
                    case 2:
                        SQLBase = "exec SPUpdExperiencia '{0}','{1}','{2}','{3}',{4}";
                        SQLFinal = string.Format(SQLBase, _idCandidato, _experiencia.Empresa,_experiencia.Años,_experiencia.Responsabilidades, _renglon);
                        break;
                    default:
                        break;
                }

                ejecutaStore(SQLFinal);
                CargaGrids();
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void agregar(int info)
        {
            string SQLBase = "";
            string SQLFinal = "";
            string SQL = "";
            try
            {
                object datos = new object();
                string titulo = "";
                switch (info)
                {
                    case 1:
                        datos = new Estudios();
                        titulo = "Estudios";
                        break;
                    case 2:
                        datos = new Experiencia();
                        titulo = "Experiencia";
                        break;
                    default:
                        break;
                }
                _renglon = 0;                
                wCurrEstudios wVentana = new wCurrEstudios((info - 1), datos);
                wVentana.Title = titulo;
                wVentana.Renglon = _renglon;
                wVentana.Show();
                wVentana.CerrarVentana += (obj1, obj2) =>
                {
                    if (obj2)
                    {
                        switch (info)
                        {
                            case 1:
                                _estudios = (Estudios)obj1;
                                SQL = string.Format("select max(renglon) + 1 as renglon from Estudios where idcandidato = '{0}'", _idCandidato);
                                _renglon = calculaRenglonSiguiente(SQL);
                                SQLBase = "exec SPInsEstudios '{0}','{1}','{2}','{3}','{4}',{5}";
                                SQLFinal = string.Format(SQLBase, _idCandidato, _estudios.Escuela, _estudios.Carrera, _estudios.Titulo, _estudios.Años, _renglon);
                                break;
                            case 2:
                                _experiencia = (Experiencia)obj1;
                                SQL = string.Format("select max(renglon) + 1 as renglon from Experiencia where idcandidato = '{0}'", _idCandidato);
                                _renglon = calculaRenglonSiguiente(SQL);
                                SQLBase = "exec SPInsExperiencia '{0}','{1}','{2}','{3}',{4}";
                                SQLFinal = string.Format(SQLBase, _idCandidato, _experiencia.Empresa, _experiencia.Años, _experiencia.Responsabilidades, _renglon);
                                break;
                            default:
                                break;
                        }
                        ejecutaStore(SQLFinal);
                        CargaGrids();
                    }
                };
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void menos(int info)
        {
            try
            {
                if (_renglon > 0)
                {
                    string SQL = "";
                    string SQLFinal = "";
                    switch (info)
                    {
                        case 1:
                            SQL = "exec SPDltEstudios '{0}',{1}";
                            break;
                        case 2:
                            SQL = "exec SPDltExperiencia '{0}',{1}";
                            break;
                        default:
                            break;
                    }
                    SQLFinal = string.Format(SQL, _idCandidato, _renglon);
                    ejecutaStore(SQLFinal);
                    CargaGrids();
                }
            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
        }

        private void upd(int info)
        {
            if (_renglon > 0)
            {
                switch (info)
                {
                    case 1:                        
                        dgEstudios_MouseDoubleClick(null, null);
                        break;
                    case 2:                        
                        dgExperiencias_MouseDoubleClick(null, null);
                        break;
                    default:
                        break;
                }
            }
        }

        private void ejecutaStore(string SQL)
        {
            bdSQLServer bd = new bdSQLServer((string)settings.GetValue("cadenaconexion", typeof(string)));
            try
            {
                bd.bdConecta();

                int iEjecuta = 0;
                iEjecuta = bd.bdEjecuta(SQL);

            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }
            finally
            {
                bd.bdCierra();
            }
        }

        private int calculaRenglonSiguiente(string SQL)
        {
            bdSQLServer bd = new bdSQLServer((string)settings.GetValue("cadenaconexion", typeof(string)));
            DataTable dt;

            int renglon = 0;
            try
            {
                bd.bdConecta();
                dt = bd.dataSetConsulta(SQL, "tabla").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0][0] != DBNull.Value)
                        renglon = int.Parse(dt.Rows[0][0].ToString());
                    else
                        renglon = 1;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                bd.bdCierra();
            }
            return renglon;
        }

        private void CargaGrids()
        {
            bdSQLServer bd = new bdSQLServer((string)settings.GetValue("cadenaconexion", typeof(string)));
            string strSQL = "";
            string strSQLFinal = "";
            try
            {
                strSQL += "select Renglon,Escuela,Carrera,Titulo,anos as Años ";
                strSQL += "from estudios ";
                strSQL += "where idcandidato = '{0}'";
                strSQL += "order by renglon asc; ";
                strSQL += "select Renglon,Empresa,anos as Años,Responsabilidades ";
                strSQL += "from Experiencia  ";
                strSQL += "where idcandidato = '{0}' ";
                strSQL += "order by renglon asc ";

                
                strSQLFinal = string.Format(strSQL, _idCandidato);

                bd.bdConecta();

                DataSet ds = bd.dataSetConsulta(strSQLFinal, "datos");

                dgEstudios.DataSource = ds.Tables[0].DefaultView;
                dgExperiencias.DataSource = ds.Tables[1].DefaultView;

            }
            catch (Exception ex)
            {
                wExcepcionesSistema wError = new wExcepcionesSistema();
                wError.txtExcepcion.Text = ex.Message;
                wError.ShowDialog();
            }

            finally
            {
                bd.bdCierra();
            }
        }

        private void btnReporteFinal_Click(object sender, RoutedEventArgs e)
        {
            wReporteFinal wRepFinal = new wReporteFinal();
            wRepFinal.IdCandidato = _idCandidato;
            wRepFinal.Show();
            //wfReporteFinal2 wrep = new wfReporteFinal2();
            //wrep.IdCandidato = _idCandidato;
            //wrep.Show();

        }
	}
}